home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / graphics / mpega_library / developer / include / libraries / mpega.h
C/C++ Source or Header  |  1999-06-15  |  5KB  |  166 lines

  1. /*------------------------------------------------------------------------------
  2.  
  3.     File    :   MPEGA.h
  4.  
  5.     Author  :   Stéphane TAVENARD
  6.  
  7.     $VER:   MPEGA.h  2.0  (21/06/1998)
  8.  
  9.     (C) Copyright 1997-1998 Stéphane TAVENARD
  10.         All Rights Reserved
  11.  
  12.     #Rev|   Date   |                      Comment
  13.     ----|----------|--------------------------------------------------------
  14.     0   |25/10/1997| Initial revision                                     ST
  15.     1   |21/06/1998| Added MPEGA_scale                                    ST
  16.  
  17.     ------------------------------------------------------------------------
  18.  
  19.     MPEGA decoder library definitions
  20.  
  21. ------------------------------------------------------------------------------*/
  22.  
  23. #ifndef LIBRARIES_MPEGA_H
  24. #define LIBRARIES_MPEGA_H
  25.  
  26. #define MPEGA_VERSION 2 /* #1 */
  27.  
  28. #ifndef EXEC_TYPES_H
  29. #include <exec/types.h>
  30. #endif
  31.  
  32. #ifndef UTILITY_HOOKS_H
  33. #include <utility/hooks.h>
  34. #endif
  35.  
  36. /* Controls for decoding */
  37.  
  38. /* Qualities */
  39. #define MPEGA_QUALITY_LOW    0
  40. #define MPEGA_QUALITY_MEDIUM 1
  41. #define MPEGA_QUALITY_HIGH   2
  42.  
  43. /*
  44.    Bitstream Hook function is called like (SAS/C syntax):
  45.  
  46.  
  47.    ULONG __saveds __asm HookFunc( register __a0 struct Hook  *hook,
  48.                                   register __a2 APTR          handle,
  49.                                   register __a1 MPEGA_ACCESS *access );
  50.  
  51.    MPEGA_ACCESS struct specify bitstream access function & parameters
  52.  
  53.    access->func == MPEGA_BSFUNC_OPEN
  54.       open the bitstream
  55.       access->data.open.buffer_size is the i/o block size your read function can use
  56.       access->data.open.stream_size is the total size of the current stream
  57.                                     (in bytes, set it to 0 if unknown)
  58.       return your file handle (or NULL if failed)
  59.    access->func == MPEGA_BSFUNC_CLOSE
  60.       close the bitstream
  61.       return 0 if ok
  62.    access->func == MPEGA_BSFUNC_READ
  63.       read bytes from bitstream.
  64.       access->data.read.buffer is the destination buffer.
  65.       access->data.read.num_bytes is the number of bytes requested for read.
  66.       return # of bytes read or 0 if EOF.
  67.    access->func == MPEGA_BSFUNC_SEEK
  68.       seek into the bitstream
  69.       access->data.seek.abs_byte_seek_pos is the absolute byte position to reach.
  70.       return 0 if ok
  71. */
  72.  
  73. #define MPEGA_BSFUNC_OPEN  0
  74. #define MPEGA_BSFUNC_CLOSE 1
  75. #define MPEGA_BSFUNC_READ  2
  76. #define MPEGA_BSFUNC_SEEK  3
  77.  
  78. typedef struct {
  79.  
  80.    LONG  func;           /* MPEGA_BSFUNC_xxx */
  81.    union {
  82.       struct {
  83.          char *stream_name; /* in */
  84.          LONG buffer_size;  /* in */
  85.          LONG stream_size;  /* out */
  86.       } open;
  87.       struct {
  88.          void *buffer;      /* in/out */
  89.          LONG num_bytes;    /* in */
  90.       } read;
  91.       struct {
  92.          LONG abs_byte_seek_pos; /* out */
  93.       } seek;
  94.    } data;
  95.  
  96. } MPEGA_ACCESS;
  97.  
  98. /* Decoding output settings */
  99.  
  100. typedef struct {
  101.    WORD freq_div;    /* 1, 2 or 4 */
  102.    WORD quality;     /* 0 (low) .. 2 (high) */
  103.    LONG freq_max;    /* for automatic freq_div (if mono_freq_div == 0) */
  104. } MPEGA_OUTPUT;
  105.  
  106. /* Decoding layer settings */
  107. typedef struct {
  108.    WORD force_mono;        /* 1 to decode stereo stream in mono, 0 otherwise */
  109.    MPEGA_OUTPUT mono;      /* mono settings */
  110.    MPEGA_OUTPUT stereo;    /* stereo settings */
  111. } MPEGA_LAYER;
  112.  
  113. /* Full control structure of MPEG Audio decoding */
  114. typedef struct {
  115.    struct Hook *bs_access;    /* NULL for default access (file I/O) or give your own bitstream access */
  116.    MPEGA_LAYER layer_1_2;     /* Layer I & II settings */
  117.    MPEGA_LAYER layer_3;       /* Layer III settings */
  118.    WORD check_mpeg;           /* 1 to check for mpeg audio validity at start of stream, 0 otherwise */
  119.    LONG stream_buffer_size;   /* size of bitstream buffer in bytes (0 -> default size) */
  120.                               /* NOTE: stream_buffer_size must be multiple of 4 bytes */
  121. } MPEGA_CTRL;
  122.  
  123. /* MPEG Audio modes */
  124.  
  125. #define MPEGA_MODE_STEREO   0
  126. #define MPEGA_MODE_J_STEREO 1
  127. #define MPEGA_MODE_DUAL     2
  128. #define MPEGA_MODE_MONO     3
  129.  
  130. typedef struct {
  131.    /* Public data (read only) */
  132.    /* Stream info */
  133.    WORD  norm;          /* 1 or 2 */
  134.    WORD  layer;         /* 1..3 */
  135.    WORD  mode;          /* 0..3  (MPEGA_MODE_xxx) */
  136.    WORD  bitrate;       /* in kbps */
  137.    LONG  frequency;     /* in Hz */
  138.    WORD  channels;      /* 1 or 2 */
  139.    ULONG ms_duration;   /* stream duration in ms */
  140.    WORD  private_bit;   /* 0 or 1 */
  141.    WORD  copyright;     /* 0 or 1 */
  142.    WORD  original;      /* 0 or 1 */
  143.    /* Decoding info according to MPEG control */
  144.    WORD  dec_channels;  /* decoded channels 1 or 2 */
  145.    WORD  dec_quality;   /* decoding quality 0..2 */
  146.    LONG  dec_frequency; /* decoding frequency in Hz */
  147.  
  148.    /* Private data */
  149.    void  *handle;
  150. } MPEGA_STREAM;
  151.  
  152. #define MPEGA_MAX_CHANNELS 2    // Max channels
  153. #define MPEGA_PCM_SIZE     1152 // Max samples per frame
  154.  
  155. /* Error codes */
  156.  
  157. #define MPEGA_ERR_NONE     0
  158. #define MPEGA_ERR_BASE     0
  159. #define MPEGA_ERR_EOF      (MPEGA_ERR_BASE-1)
  160. #define MPEGA_ERR_BADFRAME (MPEGA_ERR_BASE-2)
  161. #define MPEGA_ERR_MEM      (MPEGA_ERR_BASE-3)
  162. #define MPEGA_ERR_NO_SYNC  (MPEGA_ERR_BASE-4)
  163. #define MPEGA_ERR_BADVALUE (MPEGA_ERR_BASE-5) /* #1 */
  164.  
  165. #endif /* LIBRARIES_MPEGA_H */
  166.